package com.ikingtech.framework.sdk.datasource.model.enums;

import lombok.RequiredArgsConstructor;

/**
 * @author tie yan
 */
@RequiredArgsConstructor
public enum DatasourceSchemaTypeEnum {

    /**
     * Mysql
     */
    MYSQL("Mysql", "com.mysql.cj.jdbc.Driver", "jdbc:mysql://{}:{}/mysql?characterEncoding=utf8&allowMultiQueries=true&useSSL=false&serverTimezone=Asia/Shanghai"),

    /**
     * POSTGRES
     */
    POSTGRES("Postgres", "org.postgresql.Driver", "jdbc:postgresql://{}:{}?useSSL=false"),

    /**
     * ORACLE
     */
    ORACLE("Oracle", "oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@{}:{}"),

    /**
     * MSSQL_SERVER
     */
    MSSQL_SERVER("SQLServer", "com.microsoft.sqlserver.jdbc.SQLServerDriver", "jdbc:sqlserver://{}:{};");

    public final String description;

    public final String driverClassName;

    public final String jdbcUrl;

    public static String jdbcUrl(String databaseType, String ip, String port) {
        if (MYSQL.name().equals(databaseType)) {
            return "jdbc:mysql://" + ip + ":" + port + "/mysql?characterEncoding=utf8&allowMultiQueries=true&useSSL=false&serverTimezone=Asia/Shanghai";
        }
        if (POSTGRES.name().equals(databaseType)) {
            return "jdbc:postgresql://" + ip + ":" + port + "?useSSL=false";
        }
        if (ORACLE.name().equals(databaseType)) {
            return "jdbc:oracle:thin:@" + ip + ":" + port;
        }
        if (MSSQL_SERVER.name().equals(databaseType)) {
            return "jdbc:sqlserver://" + ip + ":" + port + ";";
        }
        return null;
    }

    public static String jdbcUrl(String databaseType, String ip, String port, String databaseName) {
        if (MYSQL.name().equals(databaseType)) {
            return "jdbc:mysql://" + ip + ":" + port + "/" + databaseName + "?characterEncoding=utf8&allowMultiQueries=true&useSSL=false&serverTimezone=Asia/Shanghai";
        }
        if (POSTGRES.name().equals(databaseType)) {
            return "jdbc:postgresql://" + ip + ":" + port + "/" + databaseName + "?useSSL=false";
        }
        if (ORACLE.name().equals(databaseType)) {
            return "jdbc:oracle:thin:@" + ip + ":" + port + ":" + databaseName;
        }
        if (MSSQL_SERVER.name().equals(databaseType)) {
            return "jdbc:sqlserver://" + ip + ":" + port + ";" + "database=" + databaseName;
        }
        return null;
    }
}
